﻿using DeHeng_Mes.Model.Table;
using GXWA_DATA.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GXWA_DATA.Model.Singleton
{
    public sealed class OrderSingleton
    {
        private static readonly Lazy<List<OrderStatus>> _instance = new Lazy<List<OrderStatus>>(() => new List<OrderStatus>());

        public static List<OrderStatus> Instance => _instance.Value;

        public OrderSingleton() { }

        public static void Add(OrderStatus orderStatus)
        {
            Instance.Add(orderStatus);

            Tools.ProduceLogText($"[{orderStatus.OrderId}]缓存成功，物料编码[{orderStatus.MaterialId}]，工单数量[{orderStatus.ProductionPlan}]，当前工单数量[{Instance.Count}]");
        }

        /// <summary>
        /// 清除缓存
        /// </summary>
        /// <param name="orderData"></param>
        public static void Delete(ApiModel.OrderApiCloseModel? orderData)
        {
            OrderStatus? orderStatus = Instance.Where(x => x.OrderId == orderData.OrderCode).FirstOrDefault();

            if (orderStatus != null)
            {
                Instance.Remove(orderStatus);
            }
        }
    }
}
